package com.qianbao.qianbaobusiness.ui.cashier;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.androidbase.utils.DisplayUtils;
import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.baseandroid.config.Constant;
import com.baseandroid.config.Global;
import com.baseandroid.utils.FormatUtil;
import com.baseandroid.utils.TimeUtils;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.SettlementDetailBean;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SettlementAdapter extends BaseRecycleViewAdapter<SettlementDetailBean.SettleMent> {

    public SettlementAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindBaseViewHolder(RecyclerView.ViewHolder holder, SettlementDetailBean.SettleMent item) {
        ViewHolder viewHolder = (ViewHolder) holder;
        if (Global.getShopListInfo().merchantList.size() > 1) {
            viewHolder.itemView.getLayoutParams().height = DisplayUtils.dp2px(125);
            viewHolder.itemView.setBackgroundResource(R.drawable.bg_shadow_settle);
            viewHolder.itemBalbanceMerchantName.setVisibility(View.VISIBLE);
            for (int i = 0; i < Global.getShopListInfo().merchantList.size(); i++) {
                if (TextUtils.equals(Global.getShopListInfo().merchantList.get(i).posMerchantNo, item.merchantCode)) {
                    viewHolder.itemBalbanceMerchantName.setText(Global.getShopListInfo().merchantList.get(i).merchantName);
                    break;
                }
            }
            viewHolder.tvSettlementDate.setTextColor(ContextCompat.getColor(mContext, R.color.text_support));
            viewHolder.tvSettlementMoney.setTextColor(ContextCompat.getColor(mContext, R.color.text_support));
            //                    viewHolder.tv_settlement_date.setTextSize(Tools.sp2px(mContext, 12));
            viewHolder.tvSettlementDate.setTextSize(12);
            viewHolder.tvSettlementMoney.setTextSize(12);
        } else {
            viewHolder.itemView.getLayoutParams().height = DisplayUtils.dp2px(105);
            viewHolder.itemView.setBackgroundResource(R.drawable.bg_shadow_settle1);
            viewHolder.tvSettlementDate.setTextColor(ContextCompat.getColor(mContext, R.color.text_important));
            viewHolder.tvSettlementMoney.setTextColor(ContextCompat.getColor(mContext, R.color.text_important));
            //                    viewHolder.tv_settlement_date.setTextSize(DisplayLess.$sp2px(14));
            viewHolder.tvSettlementDate.setTextSize(14);
            viewHolder.tvSettlementMoney.setTextSize(14);
            viewHolder.itemBalbanceMerchantName.setVisibility(View.GONE);
        }

        String time1 = item.getSettleDate();
        time1 = TimeUtils.getDate(time1, Constant.DATE_YYYYMMDD,Constant.DATE_YYYY_MM_DD);
        ((ViewHolder) holder).tvSettlementDate.setText(time1);
        try {
            String s = Double.parseDouble(item.getTotalAmt()) / 100 + "";
            s = FormatUtil.getMoneyFormat(s);
            ((ViewHolder) holder).tvSettlementMoney.setText(s);
            //                historyHolder.tv_settlement_money.setText(mContext.getResources().getString(R.string.rmb) + "99999.99");
            String cardMoney = Double.parseDouble(item.getPOSAmt()) / 100 + "";
            cardMoney = FormatUtil.getMoneyFormat(cardMoney);
            ((ViewHolder) holder).tvCardMoney.setText(cardMoney);
            //                historyHolder.tv_card_money.setText(mContext.getResources().getString(R.string.rmb) + "99999.99");

            String aliwx = (Double.parseDouble(item.getAlipayAmt()) / 100 + Double.parseDouble(item.getWechatAmt()) / 100) + "";


            aliwx = FormatUtil.getMoneyFormat(aliwx);
            ((ViewHolder) holder).tvAlivxMoney.setText(aliwx);
            //                historyHolder.tv_alivx_money.setText(mContext.getResources().getString(R.string.rmb) + "99999.99");

            String qbmd = Double.parseDouble(item.getQianbaoAmt()) / 100 + "";
            qbmd = FormatUtil.getMoneyFormat(qbmd);
            ((ViewHolder) holder).tvPayMoney.setText(qbmd);
            //                historyHolder.tv_pay_money.setText(mContext.getResources().getString(R.string.rmb) + "99999.99");
        } catch (Exception e) {
            //                historyHolder.balance_count.setText(model.getSettlementAmtTotal());
            //                historyHolder.balance_right_arraw.setVisibility(View.INVISIBLE);
        }
        ((ViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,DataBillActivity.class);
                intent.putExtra("bean",item);
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    protected RecyclerView.ViewHolder onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.item_settlement_detail,parent,false);
        return new ViewHolder(view);
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.item_balbance_merchant_name)
        TextView itemBalbanceMerchantName ;     //商铺名
        @BindView(R.id.tv_settlement_date)
        TextView tvSettlementDate ; //日期
        @BindView(R.id.tv_settlement_money)
        TextView tvSettlementMoney ;    //到账总金额
        @BindView(R.id.tv_alivx_money)
        TextView tvAlivxMoney ; //微信支付宝
        @BindView(R.id.tv_pay_money)
        TextView tvPayMoney ;   //钱包金额
        @BindView(R.id.tv_card_money)
        TextView tvCardMoney ;  //刷卡
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
